class Solution:
    def divide(self, dividend: int, divisor: int) -> int:
        if dividend==0:
            return 0
        sign=1
        if dividend<0:
            sign*=-1
            dividend=-dividend
        if divisor<0:
            sign*=-1
            divisor=-divisor
        count=0
        total=0
        pows=1
        while True:
            total+=divisor*pows
            count+=pows
            #print(total)
            if total>dividend and pows!=1:
                total-=divisor*pows
                count-=pows
                pows=1
            elif total>dividend and pows==1:
                result=(count-1)*sign
                break
            elif total==dividend:
                result=count*sign
                break
            else:
                pows*=2
        if result>2147483647 or result<-2147483648:
            return 2147483647
        else:
            return result

s=Solution()
print(s.divide(2147483648,1))

'''
执行用时：
36 ms
, 在所有 Python3 提交中击败了
90.78%
的用户
内存消耗：
14.9 MB
, 在所有 Python3 提交中击败了
5.03%
的用户
'''